package leetcode.median;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * ClassName: $438_FindAnagrams
 * Description:
 * date: 2022-02-20 19:44
 *
 * @author liyifan
 */
public class $438_FindAnagrams {
    public List<Integer> findAnagrams(String s, String p) {
        char[] oriArr = p.toCharArray();
        Arrays.sort(oriArr);
        String pSort = new String(oriArr);
        List<Integer> res = new ArrayList<>();
        int pLen = p.length();
        int sLen = s.length();
        for (int i = 0;i < sLen - pLen + 1;i++) {
            if (pSort.contains(s.charAt(i) + "")) {
                // 循环找
                int end = i + pLen;
                char[] temp = s.substring(i, end).toCharArray();
                Arrays.sort(temp);
                String tempSort = new String(temp);
                if (tempSort.equals(pSort)) {
                    res.add(i);
                }
            }
        }
        return res;
    }
}
